/*
 * 配置读写器文件
*/

#include <string>
#include <map>
#include <io.h>
#include <direct.h>
#include "ConfigGlobal.h"

class ConfigReaderWriter
{
public:
    virtual bool LoadFIle(std::string fileAddress)=0;//具体如何读取在子类实现
    virtual bool SaveFile(std::string fileAddress)=0;//具体如何保存在子类实现

    //创建多层文件夹
    virtual bool CreateDirectory(const std::string& path);
    //创建文件
    virtual bool CreateFile(const std::string& fileAddress);
protected:
    std::string m_fileAddress_ = std::string();//文件地址
};

//配置文件读写器
class IniReaderWriter:public ConfigReaderWriter
{
public:
    IniReaderWriter(std::string fileAddress = std::string());
    ~IniReaderWriter();
public:
    virtual bool LoadFIle(std::string fileAddress);
    virtual bool SaveFile(std::string fileAddress);
public:
    std::string Get(const std::string& section, const std::string& key, const std::string& defaultValue = "");
    void Set(const std::string& section, const std::string& key, const std::string& value);
    void Remove(const std::string& section, const std::string& key);
    void RemoveSection(const std::string& section);
protected:
    std::map<std::string, std::map<std::string, std::string>> m_config_;//存储 ini 具体配置
};
